package com.situ.mall.order.controller;

import com.situ.mall.base.entity.Member;
import com.situ.mall.base.service.IMemberService;
import com.situ.mall.base.service.IOrderInfoService;
import com.situ.mall.base.util.URLUtil;
import com.situ.mall.base.vo.LayuiTableVO;
import com.situ.mall.base.vo.ResVO;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * ClassName: MemberController
 * Package: com.situ.mall.order.controller
 * Description:
 *
 * @Author Darling_达
 * @Create 2023-04-16 21:39
 * @Version 1.0
 */

@Controller
@RequestMapping(URLUtil.MEMBER)
public class MemberController {

    @Autowired
    private IOrderInfoService orderInfoService;

    @Autowired
    private IMemberService memberService;

    @RequestMapping(URLUtil.PERSONAL)
    public String personal(){
        return URLUtil.PERSONAL_HTML;
    }

    @GetMapping(URLUtil.PAGE)
    public String page(){
        return URLUtil.MEMBER_INFO_HTML;
    }


    @GetMapping(URLUtil.ORDER)
    @ResponseBody
    public LayuiTableVO orderList(@RequestParam Integer page, @RequestParam Integer limit){
        return orderInfoService.orderList(page, limit);
    }

    @PostMapping(URLUtil.AVATAR)
    @ResponseBody
    public ResVO avatar(MultipartFile file) {
        return memberService.avatar(file);
    }


    @GetMapping(URLUtil.UID)
    @ResponseBody
    public Member edit(@PathVariable("id") Integer id) {
        return memberService.getById(id);
    }


    @PostMapping(URLUtil.EDIT)
    @ResponseBody
    public void edit(Member member) {
        memberService.saveOrUpdate(member);
    }


}
